Repository navigation
fix(memory): add reindex recursion and API write L1 vectorization - #3679
Open
Franch-Toast wants to merge 6 commits into
Open
Franch-Toast wants to merge 6 commits into
Franch-Toast wants to merge 6 commits into
Conversation
SessionCommit could write memory leaf files and their .overview.md without enqueuing the L1 directory vectors, leaving parent directories without vector records. Hierarchical retrieval then returned zero results until a vectors_only reindex rebuilt the subtree. Default memory files (identity.md, soul.md) written by initialize_memory_files were likewise never embedded. Two root causes: 1. generate_overview() wrote .overview.md after _vectorize_memories() ran, so the new overview file was never vectorized. 2. initialize_memory_files() wrote defaults directly through viking_fs.write_file() with no embedding enqueue. Fixes: - Reorder apply_operations so overview generation happens before _vectorize_memories; collect the written overview URIs and pass them as a new overview_uris parameter. - _vectorize_memories enqueues one L1 OVERVIEW record per overview URI via vectorize_directory_meta(include_abstract=False), reusing the shared owner/timestamp/telemetry path. No L0 abstract record is emitted because no .abstract.md was written; overview files are kept out of written_uris so the leaf flow is unchanged. - vectorize_directory_meta gains include_abstract (default True) so callers that only wrote .overview.md can skip the L0 record. - initialize_memory_files returns the list of URIs it newly created; pre-existing files are skipped and not returned. - Add MemoryUpdater.initialize_and_vectorize_default_files and use it from compressor v2/v3 so newly initialized defaults are embedded on first session. Pre-existing defaults are not re-embedded. Tests: - tests/unit/session/memory/test_issue_3640_parent_vectors.py covers initialize_memory_files return semantics, the shared v2/v3 helper (success / no-op / vikingdb-unavailable), and apply_operations emitting exactly one L1 OVERVIEW per parent while keeping the leaf at L2 DETAIL and .overview.md out of written_uris. - tests/unit/test_vectorize_file_strategy.py covers include_abstract=False producing exactly one OVERVIEW record and the default still producing L0+L1. Fixes volcengine#3640
Ruff lint fix + format over the changed test file; no behavior change.
Extends PR volcengine#3665 with two additional fixes: 1. _process_memory_directory now honors msg.recursive flag, processing subdirectories recursively during reindex. Write-path behavior is unchanged (recursive=False). 2. ContentWriteCoordinator._write_memory_with_refresh now vectorizes the direct parent directory overview as L1 after refresh_schema_overview, aligning API writes with SessionCommit path. Fixes volcengine#2797 (reindex recursion) Relates volcengine#3640 (API write path)
Author
|
@huangruiteng |
Franch-Toast
marked this pull request as draft
August 3, 2026 02:24
Franch-Toast
marked this pull request as ready for review
August 3, 2026 02:29
Author
|
The conflict caused by the v0.4.12 update has been resolved. |
Author
|
@qin-ctx Hello! Could you please take a moment to review this? Thank you! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(memory): add reindex recursion and API write L1 vectorization
Description
Extends #3665 with two additional fixes for the memory write pipeline L1 vector gap.
PR #3665 resolved the SessionCommit path (reorder overview generation before vectorization, emit L1 per parent directory), but left two gaps that this PR addresses:
Reindex recursion (
_process_memory_directory): The method previously ignoredmsg.recursive, meaningov reindexon a memory root (e.g.entities/) only processed files in the immediate directory and never descended into category subdirectories (e.g.entities/projects/). Now, whenrecursive=True, subdirectories are processed recursively with per-child error isolation.API write path L1 vectorization (
_write_memory_with_refresh): Writing a memory file via the API (e.g.ov write entities/projects/illuminator.md) generated.overview.mdfor the memory type root but never vectorized the direct parent directory overview as L1. Thinking-mode retrieval (level=[0,1]) could not discover the category directory until a manual reindex. Now the direct parent's overview is refreshed and vectorized as L1 (zero LLM cost, template-rendered only).Background — Issue Chain
.overview.mdbut never enqueues L1 vectorsov reindexon memory directories does not recurse into subdirectoriesDesign Decisions
level=[0,1], no depth limit) discovers any L1 directory regardless of depth; ancestor L1 records are created during initialization/reindexlock=Nonefor recursive childrenskip_vectorizationpropagated to childrenskip_vectorization=True; children must inherit this to avoid premature embeddingHuman Involvement
Related Issue
Relates #3640.
Fixes #2797.
Type of Change
Changes Made
openviking/storage/queuefs/semantic_processor.py—_process_memory_directorynow collects subdirectories alongside files; whenmsg.recursive=True, recursively invokes itself for each non-hidden child directory withlock=Noneand per-child error isolation (child failure logged as warning, does not block parent). Write-path behavior unchanged (recursive=Falseskips the new block entirely).openviking/storage/content_write.py—_write_memory_with_refreshnow determines the file's direct parent viaVikingURI(uri).parent; if parent differs fromroot_uri, refreshes the parent's overview and callsvectorize_directory_meta(include_overview=True, include_abstract=False)to create the L1 record. Failure is non-blocking (try/except with warning log).semantic_statuschanged from"skipped"to"partial"(L1 present, no L0).tests/unit/storage/test_memory_reindex_recursive.py— 5 new tests covering recursive behavior.tests/unit/storage/test_content_write_memory_l1.py— 5 new tests covering API write L1 vectorization.Leaf/level invariants preserved: leaf memory files continue through the standard
ContextLevel.DETAIL(L2) flow; each parent directory receives exactly oneContextLevel.OVERVIEW(L1) record withis_leaf=False,context_type="memory", and the directory URI; no L0 ABSTRACT record is emitted for memory overviews.Testing
New tests (10 total):
tests/unit/storage/test_memory_reindex_recursive.pyrecursive=Trueprocesses subdirs;recursive=Falseskips;skip_vectorizationpropagated; hidden dirs skipped; child failure isolatedtests/unit/storage/test_content_write_memory_l1.pysemantic_status="partial"Regression: All 43 pre-existing tests from PR #3665 (
test_issue_3640_parent_vectors.py+test_vectorize_file_strategy.py) pass unchanged. Total: 53 tests pass, 0 failures.Lint:
ruff checkandruff formatclean on all modified files.Checklist
Screenshots (if applicable)
N/A — backend logic changes with no UI impact.
Additional Notes
This PR is built on top of PR #3665 (cherry-picked commits
d513c6a9ande33ff176). The additional commit1f9df5fdcontains the new fixes and tests.Risk Assessment
events/year/month/day); practical recursion is bounded